//dataZoom: [{
//  type: 'slider',
//  showDataShadow: false,
//  bottom: 10,
//  height: 20,
//  borderColor: 'transparent',
//  backgroundColor: '#e2e2e2',
//  handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
//  handleSize: 20,
//  handleStyle: {
//    shadowBlur: 6,
//    shadowOffsetX: 1,
//    shadowOffsetY: 2,
//    shadowColor: '#aaa'
//  },
//  labelFormatter: ''
//}, {
//  type: 'inside'
//}],
let chartColor = ['#4E7EF4', '#FF9523', '#818CA7', '#EF4244', '#00BAB5', '#6E6BCD', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3']

function dealChart(item, mudeCode, isShowLenend, isTable) {
  if (isTable) {
    $('.title_' + item.subtopicCode).html('<div class="ml5" style="height:0.31rem;width:0.4rem;line-height: 0.38rem" onclick="Template.promptTip(\'' + item.subtopicDesc + '\', this)" ><span class="iconfont iconzhuyi-01 fs14" style="color: #B0B3B6;"></span></div>')
    if (!pm.isLogin) {
      $('#chart_' + item.subtopicCode).parent().append(`
      <div class="flex-column align-items-center pos-r table-list-login">
          <div class="flex-column justify-content-end align-items-center table-list-shadow">
              <div onclick="jsBridge.openLogin()">
                  <span class="iconfont iconwangxia table-list-loginicon"></span>
              </div>
              <div class="fs15 ff500 table-list-all" onclick="jsBridge.openLogin()">查看全部</div>
          </div>
          <div class="flex-column  align-items-center" onclick="jsBridge.openLogin()">
            <div class="fs13 table-list-lock">登录解锁更多查看权限</div>
            <div class="flex-column align-items-center justify-content-center table-list-now">
              <div>立即登录</div>
            </div>
          </div>
      </div>
    `)
    }
  } else {
    if ('1' === isShowLenend) {
      $('#childId_' + mudeCode).append('<div class=\'flex-column industry-chart-area\'><div class=\'flex-row align-items-center\'><div class="ff500 fs16">' + item.subtopicTitle + '</div><div class="ml5" style="height:0.31rem;width:0.4rem;line-height: 0.38rem" onclick="Template.promptTip(\'' + item.subtopicDesc + '\', this)" ><span class="iconfont iconzhuyi-01 fs14" style="color: #B0B3B6;"></span></div>  <div class=" flex-row justify-content-end flex-1"><div class="table-list-collect flex-row justify-content-center align-items-center " isCollect="' + item.collect + '" onclick=\'chartCollect("' + item.subtopicCode + '",this)\'><div><span class="iconfont  fs12 ' + (item.collect === '1' && pm.isLogin ? ' iconyiguanzhu-01 table-list-noc ' : ' iconguanzhu table-list-isc ') + ' " ></span></div></div></div> </div> <div id=\'chart_' + item.subtopicCode + '\'class=\'industry-chart-content\'> </div><div class=\'chart_' + item.subtopicCode + '  mt10 mb10 \'></div> </div>')
    } else {
      $('#childId_' + mudeCode).append('<div class=\'flex-column industry-chart-area\'><div class=\'flex-row align-items-center\'><div class="ff500 fs16">' + item.subtopicTitle + '</div><div class="ml5" style="height:0.31rem;width:0.4rem;line-height: 0.38rem" onclick="Template.promptTip(\'' + item.subtopicDesc + '\', this)" ><span class="iconfont iconzhuyi-01 fs14" style="color: #B0B3B6;"></span></div> <div class=" flex-row justify-content-end flex-1"><div class="table-list-collect flex-row justify-content-center align-items-center " isCollect="' + item.collect + '" onclick=\'chartCollect("' + item.subtopicCode + '",this)\'><div><span class="iconfont  fs12 ' + (item.collect === '1' && pm.isLogin ? 'iconyiguanzhu-01 table-list-noc' : ' iconguanzhu table-list-isc ') + ' " ></span></div></div></div>  </div> <div id=\'chart_' + item.subtopicCode + '\'class=\'industry-chart-content\'> </div> </div>')
    }
  }
  if (5 === item.xTimeFlag) { // 折线区域图
    lineAreaChart('chart_' + item.subtopicCode, item)
  } else if (0 === item.xTimeFlag) { // 混合柱状图、   柱状图+折线图
    mixBarChart('chart_' + item.subtopicCode, item)
  } else if (3 === item.xTimeFlag || 11 === item.xTimeFlag || 12 === item.xTimeFlag) { // 饼状图
    pieChart('chart_' + item.subtopicCode, item)
  } else if (7 === item.xTimeFlag) { // 含复工复产
    lineBar('chart_' + item.subtopicCode, item)  //混合柱状图+折线图+纵坐标两个
  } else if (8 === item.xTimeFlag) { // 含复工复产
    workProduction('chart_' + item.subtopicCode, item)  //混合柱状图+折线图+纵坐标两个
  } else if (2 === item.xTimeFlag) { //
    mixBarx('chart_' + item.subtopicCode, item)  //混合柱状图+折线图+纵坐标两个
  } else if (13 === item.xTimeFlag) {
    historyLevel('chart_' + item.subtopicCode, item)
  } else {
    lineChart('chart_' + item.subtopicCode, item) // item.xTimeFlag===4 、null
  }
  if ('1' === isShowLenend) { //如果显示图例则为1
    dealLegend('chart_' + item.subtopicCode, item)
  }

}

// 折线图
function lineChart(id, item) {
  let myChart = echarts.init(document.getElementById(id))
  let option = {
    color: chartColor,
    title: {
      text: ''
    },
    tooltip: {
      trigger: 'axis',
      confine: true,
      formatter: function (params) {
        let htmlStr = ''
        params.forEach(item => {
          if (item.value[3]) {
            htmlStr += `${item.value[3]}<br/>`
          }
          htmlStr += `<span class="fs20" style="color:${item.color}">●</span>${item.seriesName}: ${item.data[1]}${item.data[2]}` + '<br/>'
        })
        return htmlStr
      }
    },
    legend: {
      data: item.graphData.legendData,
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: item.dateUnion,
      axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
      axisLine: {show: false},
      axisTick: {show: false},
      scale: true
    },
    yAxis: [
      {
        type: 'value',
        name: '',
        axisLabel: {
          textStyle: {
            color: 'rgba(34,34,34,0.45)'
          },
        },
        axisLine: {show: false},
        axisTick: {show: false},
        formatter: '{value} ',
        splitLine: {
          show: true,
          lineStyle: {
            color: ['#F2F2F2'],
            width: 1,
            type: 'solid'
          }
        },
        scale: true
      },
      {
        type: 'value',
        name: '',
        axisLabel: {
          textStyle: {
            color: 'rgba(34,34,34,0.45)'
          },
        },
        splitLine: {
          show: false,
        },
        formatter: '{value}',
        axisLine: {show: false},
        axisTick: {show: false},
      }
    ],
    series: item.graphData.series.map((it, index) => {
      return {
        name: item.graphData.legendData[index],
        type: it.graphType,
        smooth: true,
        symbol: 'none',
        yAxisIndex: it.axisDesc,
        itemStyle: {
          normal: {
            lineStyle: {
              width: 1.5//设置线条粗细
            }
          }
        },
        data: it.data.map(function (it, index) {
          it[1] = it[1].toFixed(2)
          return it
        })
      }
    })
  }
  myChart.setOption(option)
}

function lineAreaChart(id, item) {
  // 折线图区域
  let myChart = echarts.init(document.getElementById(id))
  //指定图标的配置和区域
  let option = {
    //标题
    title: {
      text: ''
    },
    color: chartColor,

    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {}
      },
      confine: true,
      formatter: function (params) {
        let htmlStr = ''
        params.forEach(item => {
          if (item.value[3]) {
            htmlStr += `${item.value[3]}<br/>`
          }
          htmlStr += `<span class="fs20" style="color:${item.color}">●</span>${item.seriesName}: ${item.data[1]}${item.data[2]}` + '<br/>'
        })
        return htmlStr
      }
    },
    //图例
    legend: {
      data: item.graphData.legendData,  //[ '邮件营销','联盟广告','视频广告','直接访问' ],
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '13'}
    },
    grid: {
      top: '18%',
      left: '2%',
      right: '2%',
      bottom: '8%',
      borderWidth: '0',
      show: true,
      containLabel: true
    },
    //x轴数据
    xAxis: [{
      data: item.dateUnion,
      axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
      axisLine: {show: false},
      axisTick: {show: false}
    }],
    yAxis: {
      axisLine: {
        show: false
      },
      scale: true,
      axisTick: {
        show: false
      },
      axisLabel: { // 改变坐标轴上的文字颜色
        textStyle: {
          color: 'rgba(34,34,34,0.45)'
        },
        // inside: true
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ['#F2F2F2'],
          width: 1,
          type: 'solid'
        }
      }
    },
    //dataZoom: [
    //  {   // 这个dataZoom组件，默认控制x轴。
    //    //  type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
    //    //start: 10,      // 左边在 10% 的位置。
    //    // end: 60 ,        // 右边在 60% 的位置。
    //    //show:true,
    //    //  dataBackground:'red',
    //    // height:25
    //    fillerColor:'rgba(255,255,255,0)'
    //  }
    //],
    //这个部分主要为折线图区域填充
    series: item.graphData.series.map((it, index) => {
      let obj = {
        name: item.graphData.legendData[index],
        type: 'line', smooth: true, symbol: 'none',
        itemStyle: {
          normal: {
            lineStyle: {
              width: 1.5//设置线条粗细
            }
          }
        },
        data: it.data.map(function (it) {
          it[1] = it[1].toFixed(2)
          return it
        })
      }
      if (it.graphType === 'lineArea') {
        if (it.indClsName.indexOf('最小值') > -1) {
          obj.areaStyle = {opacity: 1, color: 'white'}
        } else {  //4E7EF4，18%
          obj.areaStyle = {opacity: 0.18, color: '#4E7EF4'}
        }
      }
      return obj
    }),
  }
  //渲染图表
  myChart.setOption(option)


}

//  混合柱状图 、  柱状图+折线图
function mixBarChart(id, item) {
  // 混合柱状图+折线图
  let myChart = echarts.init(document.getElementById(id))

  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      },
      confine: true,
      formatter: function (params) {
        let htmlStr = ''
        params.forEach(item => {
          if (item.value[3]) {
            htmlStr += `${item.value[3]}<br/>`
          }
          htmlStr += `<span class="fs20" style="color:${item.color}">●</span>${item.seriesName}: ${item.data[1]}${item.data[2]}` + '<br/>'
        })
        return htmlStr
      }
    },
    color: chartColor,

    legend: {
      data: item.graphData.legendData,// ['邮件营销', '联盟广告','折线图'],
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        data: item.dateUnion,
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false},
      }
    ],
    yAxis: [
      {
        type: 'value',
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false},
        splitLine: {
          show: true,
          lineStyle: {
            color: ['#F2F2F2'],
            width: 1,
            type: 'solid'
          }
        },
        scale: true
      }
    ],
    //dataZoom: [
    //  {   // 这个dataZoom组件，默认控制x轴。
    //    //  type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
    //    //start: 10,      // 左边在 10% 的位置。
    //    // end: 60 ,        // 右边在 60% 的位置。
    //    //show:true,
    //    //  dataBackground:'red',
    //    // height:25
    //    fillerColor:'rgba(255,255,255,0)'
    //  }
    //],
    series: item.graphData.series.map((it, index) => {
      return {
        name: item.graphData.legendData[index],
        type: it.graphType === 'lineArea' ? 'line' : (it.graphType === 'barStack') ? 'bar' : 'line',
        smooth: true,
        itemStyle: {
          normal: {
            lineStyle: {
              width: 1.5//设置线条粗细
            }
          }
        },
        stack: it.graphType === 'barStack' ? '总量' : item.graphData.legendData[index],
        symbol: 'none',
        barMaxWidth: 20,
        data: it.data.map(function (it, index) {
          it[1] = it[1].toFixed(2)
          return it
        })
      }
    }),
  }
  myChart.setOption(option)
}


// 饼状图
function pieChart(id, item) {
  // 饼状图
  let myChart = echarts.init(document.getElementById(id))
  let option = {
    tooltip: {
      trigger: 'item',
      // formatter: '{b}: {c} ({d}%)',
      confine: true,
      formatter: function (item) {
        let htmlStr = `${item.data.name}: ${item.data.value}${item.data.unit} (${item.percent}%)`
        return htmlStr
      }
    },
    color: chartColor,
    legend: {
      data: item.dateUnion,
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },
    series: [
      {
        name: '',
        type: 'pie',
        radius: ['50%', '70%'],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: false,
            fontSize: '30',
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: item.graphData.series.map((it, index) => {
          return {
            name: it[1],
            value: it[0],
            unit:it[2]
          }
        })
      }
    ]
  }
  myChart.setOption(option)
}


function lineBar(id, item) {
  let myChart = echarts.init(document.getElementById(id))
  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      },
      confine: true,
      formatter: function (params) {
        let htmlStr = ''
        params.forEach(item => {
          if (item.value[3]) {
            htmlStr += `${item.value[3]}<br/>`
          }
          htmlStr += `<span class="fs20" style="color:${item.color}">●</span>${item.seriesName}: ${item.data[1]}${item.data[2]}` + '<br/>'
        })
        return htmlStr
      }

    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    color: chartColor,
    toolbox: {
      feature: {
        //saveAsImage: {show: true} 下载
      }
    },

    legend: {
      data: item.graphData.legendData,
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },

    xAxis: [
      {
        type: 'category',
        axisPointer: {
          type: 'shadow'
        },
        data: item.dateUnion,
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false}
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '',
        axisLabel: {
          textStyle: {
            color: 'rgba(34,34,34,0.45)'
          },
        },
        axisLine: {show: false},
        axisTick: {show: false},
        formatter: '{value} ',
        splitLine: {
          show: true,
          lineStyle: {
            color: ['#F2F2F2'],
            width: 1,
            type: 'solid'
          }
        },
        scale: true
      },
      {
        type: 'value',
        name: '',
        //min: 0,
        //max: 25,
        // data:item.graphData.series[2].data.map(it => it[1]),
        //interval: 5,
        axisLabel: {
          textStyle: {
            color: 'rgba(34,34,34,0.45)'
          },
          // inside:true,
        },
        formatter: '{value}',
        //splitLine:{lineStyle:{color:'#F2F2F2'}}, // 是否显示分割线
        axisLine: {show: false},
        axisTick: {show: false},
      }
    ],
    series: item.graphData.series.map((it, index) => {
      return {
        name: item.graphData.legendData[index],
        type: it.graphType === 'barStack' ? 'bar' : 'line',
        smooth: true,
        markLine: {data: [{xAxis: '春节'}], lineStyle: {color: '#BDBDBD'}},
        stack: it.graphType === 'barStack' ? '总量' : item.graphData.legendData[index],
        symbol: 'none',
        yAxisIndex: it.axisDesc,
        itemStyle: {
          normal: {
            lineStyle: {
              width: 1.5//设置线条粗细
            }
          }
        },
        data: it.data.map(function (it, index) {
          it[1] = it[1].toFixed(2)
          return it
        })
      }
    })
  }
  myChart.setOption(option)
}

//复工复产
function workProduction(id, item) {
  const dateBetween = [] // 存储不同年份春节到一月一号天数
  const newDateUnion = []
  item.graphData.series.forEach(function (data) {
    const calendarDate = calendar.lunar2solar(data.indClsName.slice(0, 4), 1, 1).date
    dateBetween.push(getDaysBetween(data.indClsName.slice(0, 4) + '-1-1', calendarDate))

    data.data = changeDataDate(data.data, calendarDate, data.indClsName.slice(0, 4))
  })
  const series = item.graphData.series
  let section = 0
  const needDateIdx = series.findIndex(item => item.indClsName.indexOf('2020') > -1)
  const dateMin = section !== 0 ? -section : Number(series[needDateIdx].data[0][0])
  const dateMax = Number(series[needDateIdx].data[series[needDateIdx].data.length - 1][0])
  for (let i = dateMin; i <= dateMax; i++) {
    newDateUnion.push(i)
  }
  newDateUnion.sort((a, b) => {
    return a - b
  })
  const chuIndex = newDateUnion.findIndex(item => item === 0)
  newDateUnion[chuIndex] = '春节'
  let myChart = echarts.init(document.getElementById(id))
  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        crossStyle: {
          color: '#999'
        }
      },
      confine: true,
      formatter: function (params) {
        let htmlStr = ''
        params.forEach(item => {
          if (item.value[3]) {
            htmlStr += `${item.value[3]}<br/>`
          }
          htmlStr += `<span class="fs20" style="color:${item.color}">●</span>${item.seriesName}: ${item.data[1]}${item.data[2]}` + '<br/>'
        })
        return htmlStr
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    color: chartColor,
    toolbox: {
      feature: {
        //saveAsImage: {show: true} 下载
      }
    },

    legend: {
      data: item.graphData.legendData,
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },

    xAxis: [
      {
        type: 'category',
        axisPointer: {
          type: 'shadow'
        },
        data: newDateUnion,
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false}
      }
    ],
    yAxis: [
      {
        type: 'value',
        name: '',
        axisLabel: {
          textStyle: {
            color: 'rgba(34,34,34,0.45)'
          },
        },
        axisLine: {show: false},
        axisTick: {show: false},
        formatter: '{value} ',
        splitLine: {
          show: true,
          lineStyle: {
            color: ['#F2F2F2'],
            width: 1,
            type: 'solid'
          }
        },
        scale: true
      },
      {
        type: 'value',
        name: '',
        //min: 0,
        //max: 25,
        // data:item.graphData.series[2].data.map(it => it[1]),
        //interval: 5,
        axisLabel: {
          textStyle: {
            color: 'rgba(34,34,34,0.45)'
          },
          // inside:true,
        },
        formatter: '{value}',
        //splitLine:{lineStyle:{color:'#F2F2F2'}}, // 是否显示分割线
        axisLine: {show: false},
        axisTick: {show: false},
      }
    ],
    series: item.graphData.series.map((it, index) => {
      return {
        name: item.graphData.legendData[index],
        type: it.graphType === 'barStack' ? 'bar' : 'line',
        smooth: true,
        markLine: {data: [{xAxis: '春节'}], lineStyle: {color: '#BDBDBD'}},
        stack: it.graphType === 'barStack' ? '总量' : item.graphData.legendData[index],
        symbol: 'none',
        yAxisIndex: it.axisDesc,
        itemStyle: {
          normal: {
            lineStyle: {
              width: 1.5//设置线条粗细
            }
          }
        },
        data: it.data.map(function (it, index) {
          it[1] = it[1].toFixed(2)
          return it
        })
      }
    })
  }
  myChart.setOption(option)
}

function changeDataDate(data = [], calendarDate, years = '') {
  // 存储本年第一个数据index，之前的数据为前一年数据
  const lastYearIndex = data.findIndex(item => item[0].slice(0, 2) === '01')
  data.forEach((item, index) => {
    item.push(getDaysBetween(calendarDate, index < lastYearIndex ? Number(years) - 1 + '-' + item[0] : years + '-' + item[0]))
    item[0] = item.splice(3, 1, item[0])[0] + ''
    item.push('novel')
    item.push(index < lastYearIndex ? Number(years) - 1 : '')
  })
  const chuIndex = data.findIndex(item => item[0] === '0')
  if (chuIndex !== -1) {
    data[chuIndex][0] = '春节'
    data[chuIndex][3] = '春节'
  }
  return data
}

function getDaysBetween(dateString1, dateString2) {
  // 更改日期格式YYYY-MM-DD 为 YYYY/MM/DD 避免IE浏览器不兼容Date.parse()
  const startDate = Date.parse(dateString1.replace('-', '/').replace('-', '/'))
  const endDate = Date.parse(dateString2.replace('-', '/').replace('-', '/'))
  const days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000)
  if (days > 0) {
    return Math.round(days)
  } else {
    const newDays = Math.round(Math.abs(days))
    return 0 - newDays
  }
}

// 混合柱状图横向
function mixBarx(id, item) {
  // 混合柱状图横向
  let myChart = echarts.init(document.getElementById(id))
  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      },
      confine: true,
    },
    color: chartColor,

    legend: {
      data: item.graphData.legendData,
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'value',
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false},
      }
    ],
    yAxis: [
      {
        type: 'category',
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false},
        data: item.dateUnion,
        splitLine: {
          show: true,
          lineStyle: {
            color: ['#F2F2F2'],
            width: 1,
            type: 'solid'
          }
        }
      }
    ],
    //dataZoom: [
    //  {   // 这个dataZoom组件，默认控制x轴。
    //    //  type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
    //    //start: 10,      // 左边在 10% 的位置。
    //    // end: 60 ,        // 右边在 60% 的位置。
    //    //show:true,
    //    //  dataBackground:'red',
    //    // height:25
    //    fillerColor: 'rgba(255,255,255,0)'
    //  }
    //],

    series: item.graphData.series.map((it, index) => {
      return {
        name: item.graphData.legendData[index],
        type: it.graphType === 'baroverlap' ? 'bar' : 'line',
        smooth: true,
        stack: it.graphType === 'baroverlap' ? '总量' : item.graphData.legendData[index],
        symbol: 'none',
        itemStyle: {
          normal: {
            lineStyle: {
              width: 1.5//设置线条粗细
            }
          }
        },
        data: index > 0 ? it.data : it.data.map(its => its[2].substring(0, its[2].length - 1))
      }
    })
  }
  myChart.setOption(option)
  myChart.resize({height: item.graphData.series[0].data.length * 20 + 'px'})
}

//历史水平
function historyLevel(id, item) {

  // 混合柱状图横向
  let myChart = echarts.init(document.getElementById(id))
  let option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      },
      confine:true,
    },
    color: chartColor,

    legend: {
      data: item.graphData.legendData,
      icon: 'emptyCircle',
      left: 'auto',
      type: 'scroll',
      itemWidth: 10,
      itemHeight: 10,
      textStyle: {color: 'rgba(34,34,34,0.7)', fontSize: '12', lineHeight: '12'}
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'value',
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false},
      }
    ],
    yAxis: [
      {
        type: 'category',
        axisLabel: {textStyle: {color: '#999999'}, fontSize: '12'},
        axisLine: {show: false},
        axisTick: {show: false},
        data: item.dateUnion,
        splitLine: {
          show: true,
          lineStyle: {
            color: ['#F2F2F2'],
            width: 1,
            type: 'solid'
          }
        }
      }
    ],

    series: dealCustomData(item)
    //series: item.graphData.series.map((it, index) => {
    //  return {
    //    name: item.graphData.legendData[index],
    //    type: index === 0 ? 'bar' : 'custom', //it.graphType === 'baroverlap' ? 'bar' : 'line',
    //    smooth: true,
    //    stack: it.graphType === 'baroverlap' ? '总量' : item.graphData.legendData[index],
    //    symbol: 'none',
    //    itemStyle: {
    //      normal: {
    //        lineStyle: {
    //          width: 1.5//设置线条粗细
    //        }
    //      }
    //    },
    //    data: index > 0 ? it.data : it.data.map(its => its[1]),
    //  }
    //})
  }
  myChart.setOption(option)
  myChart.resize({height: item.graphData.series[0].data.length * 20 + 'px'})

}

function dealCustomData(item) {
  let series = []
  let obj = {}
  item.graphData.series.forEach((it, index) => {
    obj = {}
    obj.name = item.graphData.legendData[index],
    obj.type = it.graphType === 'baroverlap' ? 'bar' : 'line', //index === 0 ? 'bar' : 'custom', //
    obj.smooth = true,
    obj.stack = it.graphType === 'baroverlap' ? '总量' : item.graphData.legendData[index],
    obj.symbol = 'none',
    obj.itemStyle = {
      normal: {
        lineStyle: {
          width: 1.5//设置线条粗细
        }
      }
    }
    if (index > 0) {
      // obj.renderItem = renderItem
      obj.data = it.data
      obj.z = 2
    } else {
      obj.data = it.data.map(its => its[1])
      obj.z = 1

    }
    //obj.data = index > 0 ? it.data : it.data.map(its => its[1])
    series.push(obj)
  })
  return series
  //item.graphData.series.map((it, index) => {
  //  return {
  //    name: item.graphData.legendData[index],
  //    type: index === 0 ? 'bar' : 'custom', //it.graphType === 'baroverlap' ? 'bar' : 'line',
  //    smooth: true,
  //    stack: it.graphType === 'baroverlap' ? '总量' : item.graphData.legendData[index],
  //    symbol: 'none',
  //    itemStyle: {
  //      normal: {
  //        lineStyle: {
  //          width: 1.5//设置线条粗细
  //        }
  //      }
  //    },
  //    data: index > 0 ? it.data : it.data.map(its => its[1]),
  //  }
  //})
}

function renderItem(params, api) {
  let categoryIndex = api.value(0)
  let start = api.coord([api.value(1), categoryIndex])
  let height = api.size([0, 1])[1] * 0.6

  let rectShape = echarts.graphic.clipRectByRect({
    x: start[0],
    y: start[1] - height / 2,
    width: 2,
    height: height
  }, {
    x: params.coordSys.x,
    y: params.coordSys.y,
    width: params.coordSys.width,
    height: params.coordSys.height
  })

  return rectShape && {
    type: 'rect',
    shape: rectShape,
    style: api.style()
  }
}

function dealLegend(id, item) {
  let htmlStr = '<table class=\'industry-chart-table fs12\'>'
  for (let i = 1; i < item.tableData.length; i++) {
    if (i > 1) {
      htmlStr += '<tr class="mt10 ff600" style="height:0.5rem;line-height:0.5rem;">'
    } else {
      htmlStr += '<tr class="ff400" style="height:0.5rem;line-height:0.5rem;">'
    }
    for (let j = 1; j <= item.tableData[0].length; j++) {
      if (i === 1 && j === 1) {
        htmlStr += '<td>图例</td>'
      } else if (j === 1) {
        item.tableData.length === 3 ? htmlStr += '<td></td>' : item.xTimeFlag !== 2 ? htmlStr += '<td class="ta-center"><div class=\'industry-chart-circle\' style="border:2px solid ' + chartColor[i - 2] + '"></div></td>' : htmlStr += '<td>' + item.tableData[i]['col' + j] + '</td>'
      } else if (j >= 2 && j < item.tableData[0].length) {
        htmlStr += '<td  style="' + (i === 1 ? '' : j === 2 ? 'color:#4E7EF4' : 'color:#222222') + '">' + item.tableData[i]['col' + (j + 1)] + '</td>'
      } else {
        htmlStr += '<td  style="' + (i === 1 ? '' : j === 2 ? 'color:#4E7EF4' : 'color:#222222') + '">' + item.tableData[i]['col2'] + '</td>'
      }
    }
    htmlStr += '</tr>'
  }
  htmlStr += '</table>'
  $('.' + id).html(htmlStr)


}


function chartCollect(chartsCode, o) {
  // 如果不是登录，则跳转登录
  if (pm.isLogin) {
    let isCollect = $(o).attr('isCollect')
    isCollect = isCollect === '1' ? '0' : '1'
    Server.tableList.addOrModifyCollectionInfo({
      collectionObjectId: chartsCode,
      objectSource: 5,
      datasource: datasource,
      status: isCollect,
    }).then(function (data) {
      // 弹出收藏、取消收藏成功
      if (data.code === 0) {
        $(o).attr('isCollect', isCollect)
        $(o).html('<span class="iconfont  fs12  ' + (isCollect === '1' ? 'iconyiguanzhu-01 table-list-noc ' : 'iconguanzhu table-list-isc ') + ' " ></span>')
        jsBridge.callBridge('toast', {msg: (isCollect === '1' ? '收藏成功' : '取消收藏成功')})
      } else {
        jsBridge.callBridge('toast', {msg: (isCollect === '1' ? '收藏失败' : '取消收藏失败')})
      }
    }).catch((err) => {
      jsBridge.callBridge('toast', {msg: (isCollect === '1' ? '收藏失败' : '取消收藏失败')})
    })
  } else {
    jsBridge.openLogin()
  }
}
